#! /usr/bin/env python
#coding=utf-8

'''
用于动态导入UOC，AOC和DOC模块
'''
import udict

def UocFactory(uocname):
    "import appropriate module by uocname"
    try:
        mod = __import__("uoc." + udict.uocdict[uocname], fromlist = ['Uoc'])
        return mod
    except  Exception, e:
        return None

def AocFactory(aocname):
    "import appropriate module by aocname"
    try:
        mod = __import__("aoc." + udict.aocdict[aocname], fromlist = ['Parser'])
        return mod
    except  Exception, e:
        print str(e)
        return None
    
def DocFactory(user):
    "import DOC module by config"
    # 此方法需要user参数，显得和UocFactory，AocFactory不一致
    # 由user对象中的config.doctype来初始化Doc
    try:
        mod = __import__("doc." + user.config.doctype, fromlist = ['Doc'])
        return mod
    except  Exception, e:
        user.log.writeLog('import doc module fail.' + str(e), 'fatal')
        return None
